package com.whmskj.xjlhsc.pc.productionreport.report.service.imp;

import com.whmskj.xjlhsc.pc.productionreport.report.mapper.DayReportMapper;
import com.whmskj.xjlhsc.pc.productionreport.report.pojo.DayReportDetailVO;
import com.whmskj.xjlhsc.pc.productionreport.report.pojo.DayReportsVO;
import com.whmskj.xjlhsc.pc.productionreport.report.pojo.DetailDTO;
import com.whmskj.xjlhsc.pc.productionreport.report.service.IDayReportService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author jiaruchun
 * @date 2025-09-16 20:48
 */
@Slf4j
@Service
public class DayReportServiceImpl implements IDayReportService {
    @Autowired
    private DayReportMapper dayReportMapper;

    @Override
    public List<DayReportsVO> getDayReport(String process) {
        List<DayReportsVO> dayReport;
        if(process.equals("前纺")){
            dayReport = dayReportMapper.getQianDayReport();
        }else {
            dayReport = dayReportMapper.getDayReport(process);
        }
        log.info("dayReport:{}", dayReport);
        for (DayReportsVO dayReportsVO : dayReport) {
            //所有小数保留两位
            dayReportsVO.setEarlyOutputKm(dayReportsVO.getEarlyOutputKm() == null ? 0.0f : Float.parseFloat(String.format("%.2f", dayReportsVO.getEarlyOutputKm())));
            dayReportsVO.setEarlyOutputKg(dayReportsVO.getEarlyOutputKg() == null ? 0.0f : Float.parseFloat(String.format("%.2f", dayReportsVO.getEarlyOutputKg())));
            dayReportsVO.setEarlyPlanOutputKg(dayReportsVO.getEarlyPlanOutputKg() == null ? 0.0f : Float.parseFloat(String.format("%.2f", dayReportsVO.getEarlyPlanOutputKg())));
            dayReportsVO.setEarlyEfficiency(dayReportsVO.getEarlyEfficiency() == null ? 0.0f : Float.parseFloat(String.format("%.2f", dayReportsVO.getEarlyEfficiency())));
            dayReportsVO.setLateOutputKm(dayReportsVO.getLateOutputKm() == null ? 0.0f : Float.parseFloat(String.format("%.2f", dayReportsVO.getLateOutputKm())));
            dayReportsVO.setLateOutputKg(dayReportsVO.getLateOutputKg() == null ? 0.0f : Float.parseFloat(String.format("%.2f", dayReportsVO.getLateOutputKg())));
            dayReportsVO.setLatePlanOutputKg(dayReportsVO.getLatePlanOutputKg() == null ? 0.0f : Float.parseFloat(String.format("%.2f", dayReportsVO.getLatePlanOutputKg())));
            dayReportsVO.setLateEfficiency(dayReportsVO.getLateEfficiency() == null ? 0.0f : Float.parseFloat(String.format("%.2f", dayReportsVO.getLateEfficiency())));
            dayReportsVO.setMonthOutputKg(dayReportsVO.getMonthOutputKg() == null ? 0.0f : Float.parseFloat(String.format("%.2f", dayReportsVO.getMonthOutputKg())));
            dayReportsVO.setMonthOutputKm(dayReportsVO.getMonthOutputKm() == null ? 0.0f : Float.parseFloat(String.format("%.2f", dayReportsVO.getMonthOutputKm())));
        }
        return dayReport;
    }

    @Override
    public List<DayReportDetailVO> getDayReportDetail(DetailDTO dto) {
        return dayReportMapper.getDayReportDetail(dto);
    }
}
